package com.imchen.cms.cmscore.service;

import com.imchen.cms.cmscore.dao.TemplateMapper;
import com.imchen.cms.cmscore.model.Template;
import com.imchen.cms.exception.CmsException;
import com.imchen.cms.utils.ServiceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @author imchen
 * @create: 2019-02-13 12:17
 **/
@Service
public class TemplateService implements BaseService<Template> {

    @Autowired
    private TemplateMapper mapper;

    @Override
    public HashMap<String, Integer> add(Template template) throws CmsException {
        int count =mapper.insertSelective(template);
        int id = template.getId();
        return ServiceUtil.toAddMap(count,id);
    }

    @Override
    public Template findById(int id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public int removeById(int id) {
        return mapper.deleteByPrimaryKey(id);
    }

    @Override
    public int deleteById(int id) {
        return 0;
    }

    @Override
    public int update(Template template) {
        return mapper.updateByPrimaryKeySelective(template);
    }

    public Template findByName(String name){
        return mapper.selectByName(name);
    }
}
